import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDLordTalent {
	/**祝福id*/
	id,
	/**技能类型--1主动2被动*/
	skillType,
	/**颜色--1红2紫3蓝4黄5青*/
	color,
	/**天赋99等级解锁需求*/
	reqMSkillLv,
	/**前置天赋id*/
	reqSkill,
	/**前置天赋等级*/
	reqSkillLv,
	/**最大等级*/
	maxLv,
	/**天赋点消耗*/
	pointCost,
	/**技能id*/
	skillid,
	/**数值*/
	math,
	/**技能图标*/
	icon,

	/**枚举数量*/
	EnumCount
}



export class CDLordTalent{
	/**祝福id*/
	public id: number;
	/**技能类型--1主动2被动*/
	public skillType: number;
	/**颜色--1红2紫3蓝4黄5青*/
	public color: number;
	/**天赋99等级解锁需求*/
	public reqMSkillLv: number;
	/**前置天赋id*/
	public reqSkill: number[];
	/**前置天赋等级*/
	public reqSkillLv: number[];
	/**最大等级*/
	public maxLv: number;
	/**天赋点消耗*/
	public pointCost: number[];
	/**技能id*/
	public skillid: number;
	/**数值*/
	public math: number;
	/**技能图标*/
	public icon: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDLordTalent.id: return this.id;
			case E_CDLordTalent.skillType: return this.skillType;
			case E_CDLordTalent.color: return this.color;
			case E_CDLordTalent.reqMSkillLv: return this.reqMSkillLv;
			case E_CDLordTalent.reqSkill: return this.reqSkill;
			case E_CDLordTalent.reqSkillLv: return this.reqSkillLv;
			case E_CDLordTalent.maxLv: return this.maxLv;
			case E_CDLordTalent.pointCost: return this.pointCost;
			case E_CDLordTalent.skillid: return this.skillid;
			case E_CDLordTalent.math: return this.math;
			case E_CDLordTalent.icon: return this.icon;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDLordTalent.id: this.id = v; break;
			case E_CDLordTalent.skillType: this.skillType = v; break;
			case E_CDLordTalent.color: this.color = v; break;
			case E_CDLordTalent.reqMSkillLv: this.reqMSkillLv = v; break;
			case E_CDLordTalent.reqSkill: this.reqSkill = v; break;
			case E_CDLordTalent.reqSkillLv: this.reqSkillLv = v; break;
			case E_CDLordTalent.maxLv: this.maxLv = v; break;
			case E_CDLordTalent.pointCost: this.pointCost = v; break;
			case E_CDLordTalent.skillid: this.skillid = v; break;
			case E_CDLordTalent.math: this.math = v; break;
			case E_CDLordTalent.icon: this.icon = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDLordTalent> = new HashMap<number, CDLordTalent>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDLordTalent[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDLordTalent();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].skillType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].color = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].reqMSkillLv = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].reqSkill = [];
			const attrArray = list[i].reqSkill;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].reqSkillLv = [];
			const attrArray = list[i].reqSkillLv;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].maxLv = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].pointCost = [];
			const attrArray = list[i].pointCost;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].skillid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].math = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDLordTalent{
		return this.datas ? this.datas.get(id) : null;
	}
}
